package cn.edu.ljl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

// 获取update填写的成绩信息，进行添加

public class getupdate extends HttpServlet {

    private static final String UPDATE_TEMPLATE =
            "update grade set numbb=%s,nam ='%s',subje='%s',score=%s,feel='%s' where id = " ;


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String number = request.getParameter("numbb");
        String name   = request.getParameter("nam");
        String subject= request.getParameter("subje");
        String score  = request.getParameter("score");
        String feel   = request.getParameter("feel");
        //String pic    = request.getParameter("pic");

        String id1 = update.ID;

        String sql = String.format(UPDATE_TEMPLATE,number,name,subject,score,feel);
        String sql1 = sql + id1;
        System.out.println(sql1);

        try {
            DBMS.update(sql1);
            response.sendRedirect("./list");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
